<?php
/**
 * Created by PhpStorm.
 * User: dengpan
 * Date: 2016/12/5
 * Time: 17:37
 */

$GLOBALS['THRIFT_ROOT'] = 'thrift0.8';

require_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php';
require_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php';
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TSocket.php';
require_once $GLOBALS['THRIFT_ROOT'].'/transport/THttpClient.php';
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TFramedTransport.php';

require_once "myService.php";

try {

    $socket = new TSocket('127.0.0.1', 1234);


    $transport = new TBufferedTransport($socket, 1024, 1024);
/*
    //tnoblocking server需要
    $transport = new TFramedTransport($socket);
    */

    $transport->open();
    $protocol = new TBinaryProtocol($transport);
    $client = new Services\Hello\myServiceClient($protocol);
    $arr = [
        'count' => 12,
        'name' => "你好",
    ];

    $req = new Services\Hello\Req($arr);
    $ret = $client->getStudents($req);

    var_dump($ret);
} catch (Exception $e) {
    echo var_dump($e);
}
